package com.muyu.cloud.commodity.controller;

import com.muyu.cloud.commodity.domain.model.SpecGroupListModel;
import com.muyu.cloud.commodity.domain.req.SpecGroupSaveReq;
import com.muyu.cloud.commodity.domain.req.SpecGroupListReq;
import com.muyu.cloud.commodity.domain.resp.SpecGroupListResp;
import com.muyu.cloud.commodity.service.SpecGroupService;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.page.DataPageResp;
import com.muyu.common.core.web.page.PageQueryModel;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author <a href="mailto:602048165@qq.com">60204</a>
 * @version 1.0
 * @description:
 * @date 2025/9/15 20:25
 */
@RestController
@RequestMapping("/product/spec/group")
@Tag(name = "SpecGroupController",description = "商品规格组管理")
public class SpecGroupController {
    @Autowired
    private SpecGroupService specGroupService;

    /**
     * 获取规格组分页列表
     * @param req
     * @return
     */
    @Operation(summary = "获取规格组分页列表")
    @PostMapping("/list")
    public Result<DataPageResp<SpecGroupListResp>> list(@RequestBody SpecGroupListReq req){
        PageQueryModel<SpecGroupListModel>pageQueryModel=specGroupService.pageQuery(req);
        return Result.success(DataPageResp.of(pageQueryModel).cover(SpecGroupListResp::listBuild));
    }

    /**
     * 规格添加
     * @param req
     * @return
     */
    @Operation(summary = "保存规格组（含规格值）")
    @PostMapping("/save")
    public Result<Void> save(@RequestBody SpecGroupSaveReq req){
        specGroupService.saveWithValues(req);
        return Result.success();
    }
}
